<template>
  <!-- gy8修改 -->
  <div class="column">
    <router-view/>
    <div class="panelAll">
      <div class="boxb"><h2>规模以上工业分行业产值</h2></div>
      <!--
      v-table prop:model => 0:默认 1:头 2:只取有id的
      :sort 按照什么字段排序
      :show-flag 控制只显示前10
      :flag-id 控制是否单独生成id字段
      -->
      <v-table :sort="'currentAccumulate'"
               :model="1"
               :limit="true"
               :flag-id="true" :header="this.header" :body="this.body"/>
      <div class="panelSmLonggy-foot"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "gy8",
  mounted() {
    //传递日期
    this.bus.$emit('year', this.year)
  },
  computed: {
    year() {
      return this.$store.year
    },
    month() {
      return this.$store.month
    }
  },
  watch: {
    '$store.time': {
      immediate: true,
      deep: true,
      handler(v) {
        this.getdata()
        this.testa()
      }
    }
  },
  methods: {
    getdata() {
      this.a = 0;
      this.header[1].name = this.month + '' + '月当月(万元)'
      this.header[2].name = this.month + '' + '月止累计(万元)'
      //表格请求!
      // this.$util.http.get('/ece/getSectorProduct?year=' + this.year + '&&month=' + this.month).then(res => {
      this.$util.http.get('/excel/08/info/' + this.year + '/' + this.month).then(res => {
        this.a = 1;
        res.data[0].name = '总计'
        this.body = res.data
        // 取整
        if (res.data.length !== 0) {
          for (let obj in res.data) {
            //取整
            // res.data[obj].currentMonth = res.data[obj].currentMonth.toFixed(0)
            // res.data[obj].currentAccumulate = res.data[obj].currentAccumulate.toFixed(0)
            // res.data[obj].monthOnMothAccumulate = res.data[obj].monthOnMothAccumulate.toFixed(1)
            //当月累计/总累计
            res.data[obj].percent = ((res.data[obj].currentMonth / res.data[obj].currentAccumulate) * 100).toFixed(1)
          }
        }


      })
    },
    testa() {
      if (this.a == 0) {
        this.body = []
      }
    },
  },

  data() {
    return {
      showFlag: false,
      a: 0,

      header: [
        {
          name: "企业名称",
          value: "name",
        },
        {
          name: "八月当月(亿元)",
          value: "gyczCurrentmonth",
        },
        {
          name: "八月止累计(亿元)",
          value: "gyczCurrentaccumulate",
        },
        {
          name: "当月同比(±%)",
          value: "gyczMonthonmonth1",
        },
        {
          name: "累计同比(±%)",
          value: "gyczMonthonmonth2",
        }
      ],


      body: [],
    }
  }
}
</script>

<style scoped>
</style>